package b.b.g.i;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import androidx.appcompat.app.AlertController.b;
import androidx.appcompat.view.menu.ExpandedMenuView;
import b.b.c.f;
import java.util.ArrayList;
import java.util.Objects;

/* compiled from: ListMenuPresenter */
public class e implements m, OnItemClickListener {
    public Context a;
    public LayoutInflater b;
    public g c;
    public ExpandedMenuView d;
    public b.b.g.i.m.a e;
    public a f;

    /* compiled from: ListMenuPresenter */
    public class a extends BaseAdapter {
        public int a = -1;

        public a() {
            a();
        }

        public void a() {
            g gVar = e.this.c;
            i iVar = gVar.v;
            if (iVar != null) {
                gVar.i();
                ArrayList arrayList = gVar.j;
                int size = arrayList.size();
                for (int i = 0; i < size; i++) {
                    if (((i) arrayList.get(i)) == iVar) {
                        this.a = i;
                        return;
                    }
                }
            }
            this.a = -1;
        }

        /* renamed from: b */
        public i getItem(int i) {
            g gVar = e.this.c;
            gVar.i();
            ArrayList arrayList = gVar.j;
            Objects.requireNonNull(e.this);
            i += 0;
            int i2 = this.a;
            if (i2 >= 0 && i >= i2) {
                i++;
            }
            return (i) arrayList.get(i);
        }

        public int getCount() {
            g gVar = e.this.c;
            gVar.i();
            int size = gVar.j.size();
            Objects.requireNonNull(e.this);
            size += 0;
            return this.a < 0 ? size : size - 1;
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                view = e.this.b.inflate(2131492880, viewGroup, false);
            }
            ((b.b.g.i.n.a) view).d(getItem(i), 0);
            return view;
        }

        public void notifyDataSetChanged() {
            a();
            super.notifyDataSetChanged();
        }
    }

    public e(Context context, int i) {
        this.a = context;
        this.b = LayoutInflater.from(context);
    }

    public void a(g gVar, boolean z) {
        b.b.g.i.m.a aVar = this.e;
        if (aVar != null) {
            aVar.a(gVar, z);
        }
    }

    public ListAdapter b() {
        if (this.f == null) {
            this.f = new a();
        }
        return this.f;
    }

    public void c(Context context, g gVar) {
        if (this.a != null) {
            this.a = context;
            if (this.b == null) {
                this.b = LayoutInflater.from(context);
            }
        }
        this.c = gVar;
        a aVar = this.f;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    public boolean e(r rVar) {
        if (!rVar.hasVisibleItems()) {
            return false;
        }
        h hVar = new h(rVar);
        b.b.c.f.a aVar = new b.b.c.f.a(rVar.a);
        e eVar = new e(aVar.a.a, 2131492880);
        hVar.c = eVar;
        eVar.e = hVar;
        g gVar = hVar.a;
        gVar.b(eVar, gVar.a);
        ListAdapter b = hVar.c.b();
        b bVar = aVar.a;
        bVar.q = b;
        bVar.r = hVar;
        View view = rVar.o;
        if (view != null) {
            bVar.e = view;
        } else {
            bVar.c = rVar.n;
            bVar.d = rVar.m;
        }
        bVar.o = hVar;
        f a = aVar.a();
        hVar.b = a;
        a.setOnDismissListener(hVar);
        LayoutParams attributes = hVar.b.getWindow().getAttributes();
        attributes.type = 1003;
        attributes.flags |= 131072;
        hVar.b.show();
        b.b.g.i.m.a aVar2 = this.e;
        if (aVar2 != null) {
            aVar2.b(rVar);
        }
        return true;
    }

    public void f(boolean z) {
        a aVar = this.f;
        if (aVar != null) {
            aVar.notifyDataSetChanged();
        }
    }

    public boolean h() {
        return false;
    }

    public boolean i(g gVar, i iVar) {
        return false;
    }

    public boolean j(g gVar, i iVar) {
        return false;
    }

    public void k(b.b.g.i.m.a aVar) {
        this.e = aVar;
    }

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        this.c.s(this.f.getItem(i), this, 0);
    }
}
